<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<%@include file="/comm/pub.inc"%>
		<script type="text/javascript">
			$(function(){
				if (window.self != window.top)
					window.top.location.href=window.location.href;
			
				mini.get("loginWindow").show(null,150);
				
				new mini.Form("#loginWindow").setData({loginName:"dong",password:"max_dong"});
				onLoginClick();
				
			});
			function onPwdValidation(e) {
	            if (e.isValid) {
	                if (e.value.length < 5) {
	                    e.errorText = "密码不能少于5个字符";
	                    e.isValid = false;
	                }
	            }
	        }
	        function onResetClick(e) {
	            var form = new mini.Form("#loginWindow");
	            form.clear();
	        }
	        function onLoginClick(e) {
	            var form = new mini.Form("#loginWindow");
	            form.validate();
	            if (form.isValid() == false) return;
	            requestLogin(form.getData(),function(){
	            	window.location.href = contextPath+"/web/console.jsp";
	            });
	        }
	        function requestLogin(formData,callback){
	        	$.ajax({
				    url: contextPath+"/action/system/user/login",
				    type: "post",
				    dataType:"json",
				    data:formData,
				    success: function (result) {
					    if (result){
					        if (result.error){
					        	mini.alert(result.result);
					        }else if (result.success){
					        	if (callback){
					        		callback(result)
					        	}else{
					        		mini.alert(result.result);
					        	}
					        }
					   	}else
					   		callback && callback(result);
				    },
				    beforeSend:function(){
				    	msgBoxID = mini.loading("登录中...","提示");
				    },
				    complete:function(){
				    	mini.hideMessageBox(msgBoxID);
				    }
				    
				});
	        }
		</script>
	</head>
	<body>
	<div id="loginWindow" class="mini-window" title="用户登录" style="width:350px;height:180px;top:100px;" 
   		showModal="true" showCloseButton="false" allowDrag="false" >
    <div id="loginForm" style="padding:15px;padding-top:10px;">
        <table >
            <tr>
                <td style="width:60px;"><label for="username$text">帐号：</label></td>
                <td>
                    <input id="username" name="loginName" class="mini-textbox" required="true" style="width:180px;"/>
                </td>    
            </tr>
            <tr>
                <td style="width:60px;"><label for="pwd$text">密码：</label></td>
                <td>
                    <input id="pwd" name="password" onvalidation="onPwdValidation" class="mini-password" 
                    requiredErrorText="密码不能为空" required="true" style="width:180px;" onenter="onLoginClick"/>
                </td>
            </tr>
			<tr>
				<td></td>
				<td style="padding-top: 5px;">
					<a onclick="onLoginClick" class="mini-button"
						style="width: 60px;">登录</a>
					<a onclick="onResetClick" class="mini-button"
						style="width: 60px;">重置</a>
				</td>
			</tr>
		</table>
    </div>

</div>
	</body>
</html>
